/*--------------------劳务模块.班组管理--ly-----------------*/
/*--------------------班组信息修改功能 lb_team_edit.html------------------*/

$(document).ready(function() {
	//获取cookie:ueserid & Wtid
	var teamid = $.cookie("teamid");
	var editcookie = $.cookie("nav");
	var Wtid = JSON.parse(editcookie).w;

	//填充数据
	var searchurl = laborport + '/LabourTeamController/selectById'; //查询
	$.post(searchurl, {
		'teamId': teamid,
	}, function(result) {
		var code = result.code;
		var editlist = result.object;
		if(code == 0) {
			$("#L_teamname").val(editlist.teamname); //班组名称
			$("#L_description").val(editlist.description); //班组简介
		} else {
			console.log("网络不佳，稍后再试！")
		}
	});

	//layui
	layui.use(['form', 'layer'], function() {
		$ = layui.jquery;
		var form = layui.form,
			layer = layui.layer;

		//自定义验证规则
		form.verify({
			username: function(value) {
				if(value.length < 3) {
					return '昵称至少得5个字符啊';
				}
			},
		});

		//获取表单数据
		$("input").blur(function() {
			//失去焦点事件
			var teamname = $("#L_teamname").val(); //工种名称
			var description = $("#L_description").val(); //技能描述
			//监听提交
			form.on('submit(edit)', function() {
				//递交修改
				editData(teamname, description);
				return false;
			});
		});

		//修改用户信息
		var editurl = laborport + '/LabourTeamController/update'; //修改
		// 获得frame索引
		var index = parent.layer.getFrameIndex(window.name);
		var editData = function(teamname,description) {
			console.log(teamname, description);
			//修改 edit
			$.post(editurl, {
				teamid: teamid,
				teamname: teamname,
				description: description,
			}, function(result) {
				var code = result.code;
				if(code == 0) {
					layer.msg('修改成功!', {
						icon: 1,
						time: 1000
					}, function() {
						//关闭当前frame
						parent.layer.close(index);
					});
				} else {
					layer.msg('网络开小差了，请稍后再试!', {
						icon: 2,
						time: 1000
					}, function() {
						//关闭当前frame
//						parent.layer.close(index);
					});
				}
			})
		}

	});
})